/**
 * 添加或者修改页面
 */
var ShelfInfoDlg = {
    data: {
        id: "",
        shelvesNum: "",
        shelvesName: "",
        warehouseId: "",
        warehouseName: "",
        productId: "",
        productName: "",
        region: "",
        row: "",
        floor: "",
        mark: "",
        status: "",
        remark: "",
        handleUser: "",
        createTime: "",
        createUser: "",
        auditUser: "",
        auditTime: "",
        updateTime: "",
        printTime: "",
        updateUser: "",
        isDelete: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate','upload','formSelects'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;


    $.ajax({
        url: '/baseCommonSelect/initWarehouseInfos',
        dataType: 'json',
        // data: {"enumCode": "WarehouseType"},
        type: 'post',
        success: function(data) {
            if (data!== null) {
                $("#warehouseNameSelect").empty();
                $("#warehouseNameSelect").append(new Option());
                $.each(data, function(index, item) {
                    $('#warehouseNameSelect').append(new Option(item.value,item.id));
                });
            } else {
                $("#warehouseNameSelect").append(new Option("暂无数据", ""));
            }
            //重新渲染
            form.render("select");
        }
    });



    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        //获取选中的值
        var warehouseId = $("#warehouseNameSelect").val();
        //获取选中文本
        var warehouseName = $("#warehouseNameSelect").find("option:selected").text();

        data.field.warehouseId = warehouseId;
        data.field.warehouseName = warehouseName;

        var ajax = new $ax(Feng.ctxPath + "/shelf/addItem", function (data) {
            Feng.success("添加成功！");
            //传给上个页面，刷新table用
            admin.putTempData('formOk', true);
            //关掉对话框
            admin.closeThisDialog();
        }, function (data) {
            Feng.error("添加失败！" + data.responseJSON.message)
        });
        ajax.set(data.field);
        ajax.start();

        return false;
    });


});